﻿#region Using directives

using System;
using System.Reflection;
using NetROS.Tiers.Entities.Validation;

#endregion

namespace NetROS.Tiers.Entities
{	
	///<summary>
	/// An object representation of the 'tblBlagajna' table. [No description found the database]	
	///</summary>
	/// <remarks>
	/// This file is generated once and will never be overwritten.
	/// </remarks>	
	[Serializable]
	[CLSCompliant(true)]
	public partial class Blagajna : BlagajnaBase
	{		
		#region Constructors

		///<summary>
		/// Creates a new <see cref="Blagajna"/> instance.
		///</summary>
		public Blagajna():base(){}	
		
		#endregion
                 protected override void AddValidationRules()
        {
            base.AddValidationRules();
            ValidationRules.AddRule(
                CommonRules.StringRequired,
                new ValidationRuleArgs("Naziv", "Naziv"));
            ValidationRules.AddRule(
            CheckIsIDNotSet,
             new ValidationRuleArgs("IDKonto", "Konto"));
            ValidationRules.AddRule(
            CheckIsIDNotSet,
             new ValidationRuleArgs("IDOrganizacija", "Mjesto troška"));
            ValidationRules.AddRule(
            CheckIsIDNotSet,
             new ValidationRuleArgs("IDVrstaFinDokumenta", "Mjesto troška"));
                    
        }
         bool CheckIsIDNotSet(object target, ValidationRuleArgs e)
        {
            bool result = true;

            PropertyInfo p = target.GetType().GetProperty(e.PropertyName);

                int value = (int)p.GetValue(target, null);

                result = !value.Equals(0);

                if (!result)
                {
                    if (string.IsNullOrEmpty(e.Description)) e.Description = string.Format("Izaberite {0}",e.FriendlyName);
                }

                return result;
            
        }
	}
}
